#include "main.h"

void calculateMenu() {
    int choice;
    double voltage, resistance;
    cout << "\033c";
    std::cout << "\n------ Half/Full Wave Rectifier Circuit Calculator ------\n";
    std::cout << "|\t\t\t\t\t\t\t|\n";
    std::cout << "|\t\t1. Half-wave rectification\t\t|\n";
    std::cout << "|\t\t2. Full-wave rectification\t\t|\n";
    std::cout << "|\t\t3. Exit\t\t|\n";
    std::cout << "|\t\t\t\t\t\t\t|\n";
    std::cout << "---------------------------------------------------------\n";
    std::cout << "\nPlease select the waveform rectification type.\n\n";
    std::cout << "Please enter (Only enter number): ";
    std::cin >> choice;

    if (choice != 1 && choice != 2 && choice != 3) {
        std::cerr << "Invalid selection, please try again!\n";
    }

    if (choice == 3) {
        return;
    } 
    std::cout << "\n1. Please enter Input Voltage (in V): ";
    std::cin >> voltage;
    std::cout << "2. Please enter Load Resistance (in Ω): ";
    std::cin >> resistance;
    cout << "\033c";
    Rectifier* rectifier = nullptr;

    if (choice == 1) {
        rectifier = new HalfWaveRectifier(voltage, resistance);
        std::cout << "\nYou choose the Half-wave rectification.\n";
    } else if (choice == 2) {
        rectifier = new FullWaveRectifier(voltage, resistance);
        std::cout << "\nYou choose the Full-wave rectification.\n";
    } 
    rectifier->rectification();
    delete rectifier;

}